<template>
  <div>
    <div>tom:{{ count }}</div>
    <button @click="add">+1</button>
  </div>
</template>

<script>
import bus from '@/utils/eventBus'
export default {
  data() {
    return {
      // count: 0
    }
  },
  computed: {
    count() {
      return this.$store.state.tomCount
    }
  },
  mounted() { // 接受消息
    bus.$on('add-tom', (data) => {
      this.count += data
    })
  },
  methods: { // 发送消息
    add() {
      // bus.$emit('add-jerry', 1)
      // 可以修改不推荐,违反vuex单项数据流
      //  this.$store.state.jerryCount +=1
      this.$store.commit('addJerry', 1)
    }
  }
}
</script>

<style>

</style>
